#ifndef GA_THREADED_POPULATION_EVALUATOR_H
#define GA_THREADED_POPULATION_EVALUATOR_H

#include "../../thread/Mutex.h"
#include "../../thread/Thread.h"

#include "PopulationEvaluator.h"

namespace GA {
class Individual;
class ThreadedPopulationEvaluator : public PopulationEvaluator {
public:
	/* ctor */
	ThreadedPopulationEvaluator(int nPopulation, Individual** population);

	/* evaluate */
	void evaluate();

private:
	int          _nPopulation; /* population size */
	Individual** _population;  /* population      */

	int   _populationIndex; /* population index */
	Mutex _populationMutex; /* population mutex */

	Individual* _getNextIndividual(); /* next individual */

	/* population evaluator thread */
	class PopulationEvaluatorThread : public Thread {
	public:
		/* ctor */
		PopulationEvaluatorThread(ThreadedPopulationEvaluator& evaluator);

		/* run */
		void run();

	private:
		ThreadedPopulationEvaluator& _evaluator; /* evaluator */
	};
};

} // GA

#endif // GA_THREADED_POPULATION_EVALUATOR_H

